home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / os2tools / bnklysrc / b_wzsend.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-06  |  9.6 KB  |  255 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello  */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                    BinkleyTerm "SendWaZOO" Processor                     */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*    For complete  details  of the licensing restrictions, please refer    */
  17. /*    to the License  agreement,  which  is published in its entirety in    */
  18. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.210.    */
  19. /*                                                                          */
  20. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  21. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  22. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  23. /*    NOT HAVE THESE FILES,  YOU SHOULD  IMMEDIATELY CONTACT THE AUTHORS    */
  24. /*    AT THE  ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO    */
  25. /*    USE   THIS  FILE  WITHOUT  HAVING   ACCEPTED  THE  TERMS  OF   THE    */
  26. /*    BINKLEYTERM  LICENSING AGREEMENT,  OR SUCH OTHER  AGREEMENT AS YOU    */
  27. /*    ARE ABLE TO REACH WITH THE AUTHORS.                                   */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /*    The Authors can be reached at the following addresses:                */
  31. /*                                                                          */
  32. /*    Robert C. Hartman                      Vincent E. Perriello           */
  33. /*    Spark Software                         VEP Software                   */
  34. /*    427-3 Amherst Street                   111 Carroll Street             */
  35. /*    CS2032, Suite 232                      Naugatuck, CT 06770            */
  36. /*    Nashua, NH 03061                                                      */
  37. /*                                                                          */
  38. /*    FidoNet 1:132/101                      FidoNet 1:141/491              */
  39. /*    Data    (603) 888-8179                 Data    (203) 729-7569         */
  40. /*                                                                          */
  41. /*    Please feel free to contact us at any time to share your comments     */
  42. /*    about our software and/or licensing policies.                         */
  43. /*                                                                          */
  44. /*                                                                          */
  45. /*  This module is based largely on a similar module in OPUS-CBCS V1.03b.   */
  46. /*  The original work is (C) Copyright 1987, Wynn Wagner III. The original  */
  47. /*  author has graciously allowed us to use his code in this work.          */
  48. /*                                                                          */
  49. /*--------------------------------------------------------------------------*/
  50.  
  51. #include <signal.h>
  52. #include <ctype.h>
  53. #include <conio.h>
  54. #include <string.h>
  55.  
  56. #define WAZOO_SECTION
  57. #include "com.h"
  58. #include "xfer.h"
  59. #include "zmodem.h"
  60. #include "keybd.h"
  61. #include "sbuf.h"
  62. #include "sched.h"
  63. #include "externs.h"
  64. #include "prototyp.h"
  65.  
  66. #define rb_plus "r+b"
  67.  
  68. int WaZOO_callback (char *);
  69. static int fsent;
  70.  
  71. #define NUM_FLAGS 4
  72.  
  73.  
  74. /*--------------------------------------------------------------------------*/
  75. /* SEND WaZOO (send another WaZOO-capable Opus its mail)                    */
  76. /*   returns TRUE (1) for good xfer, FALSE (0) for bad                      */
  77. /*   use instead of n_bundle and n_attach for WaZOO Opera                   */
  78. /*--------------------------------------------------------------------------*/
  79. int send_WaZOO ()
  80. {
  81.    char fname[80];
  82.    char s[80];
  83.    char *HoldName;
  84.    int c;
  85.    struct stat buf;
  86.  
  87.  
  88.    fsent = 0;
  89.  
  90.    HoldName = HoldAreaNameMunge(called_zone);
  91.  
  92.    /*--------------------------------------------------------------------*/
  93.    /* Send all waiting ?UT files (mail packets)                          */
  94.    /*--------------------------------------------------------------------*/
  95.    *ext_flags = 'O';
  96.    for (c = 0; c < NUM_FLAGS; c++)
  97.       {
  98. #ifndef JACK_DECKER
  99.       if (caller && (ext_flags[c] == 'H'))
  100.          continue;
  101. #endif
  102.  
  103.       sprintf (fname,
  104.                "%s%04x%04x.%cUT",
  105.                HoldName, called_net, called_node, ext_flags[c]);
  106.       errno = 0;
  107.  
  108.       if (!stat (fname, &buf))
  109.          {
  110.  
  111.          /*--- Build a dummy PKT file name */
  112.          invent_pkt_name (s);
  113.  
  114.          /*--- Tell ZModem to handle this as a SEND AS then DELETE */
  115.          status_line (PACKET_msg);
  116.  
  117.          if (!(*wzsendfunc) (fname, s, fsent++, DO_WAZOO))
  118.             {
  119.             net_problems = 1;
  120.             return FALSE;
  121.             }
  122.           CLEAR_IOERR ();
  123.           unlink (fname);
  124.           got_error (UNLINK_msg, fname);
  125.          }
  126.       }                                          /* for */
  127.  
  128.    /*--------------------------------------------------------------------*/
  129.    /* Send files listed in ?LO files (attached files)                    */
  130.    /*--------------------------------------------------------------------*/
  131.    *ext_flags = 'F';
  132.    if (!do_FLOfile (ext_flags, WaZOO_callback))
  133.       return FALSE;
  134.  
  135.    /*--------------------------------------------------------------------*/
  136.    /* Send our File requests to other system                             */
  137.    /*--------------------------------------------------------------------*/
  138.    if (requests_ok)
  139.       {
  140.       sprintf (fname, request_template, HoldName, called_net, called_node);
  141.       if (!stat (fname, &buf))
  142.          {
  143.          if (!(remote_capabilities & WZ_FREQ))
  144.             status_line ("*F.REQ. declined");
  145.          else
  146.             {
  147.             status_line ("*Making file request");
  148.             ++made_request;
  149.             if ((*wzsendfunc) (fname, NULL, fsent++, DO_WAZOO))
  150.                unlink (fname);
  151.             }
  152.          }
  153.       }
  154.  
  155.    fsent = respond_to_file_requests (fsent, WaZOO_callback);
  156.  
  157.    errno = 0;
  158.    if (!fsent)
  159.       status_line (NothingToSend_msg,
  160.                    alias[assumed].Zone, alias[assumed].Net, alias[assumed].Node,
  161.                    called_zone, called_net, called_node);
  162.  
  163.    (*wzsendfunc) (NULL, NULL, ((fsent) ? END_BATCH : NOTHING_TO_DO), DO_WAZOO);
  164.  
  165.    sent_mail = 1;
  166.  
  167.    return TRUE;
  168.  
  169. }                                                /* WaZOO */
  170.  
  171. /*--------------------------------------------------------------------------*/
  172. /* RESPOND TO FILE REQUEST                                                  */
  173. /*--------------------------------------------------------------------------*/
  174. int respond_to_file_requests (f_sent, callback)
  175. int f_sent;
  176. int (*callback)(char *);
  177. {
  178.    char req[80];
  179.    struct stat buf;
  180.    int n_frproc (char *, int, int (*)(char *));
  181.    int nfiles = 0;
  182.    FILE *fp;
  183.    int np;
  184.    byte *s;
  185.  
  186.    fsent = f_sent;                              /* copy into local var  */
  187.                                                 /* this is for callback */
  188.    if (!(matrix_mask & TAKE_REQ))
  189.       goto done;
  190.  
  191.    for (np = 0; np <= ALIAS_CNT; np++)
  192.       {
  193.       if (alias[np].Net == 0)
  194.          break;
  195.  
  196.       sprintf (req, request_template, CurrentNetFiles,
  197.                alias[np].Net, alias[np].Node);
  198.  
  199.       if (!stat (req, &buf))
  200.          {
  201.          errno = 0;
  202.          fp = fopen (req, read_ascii);
  203.          if (got_error (OPEN_msg, req))
  204.             goto done;
  205.          while (!feof (fp))
  206.             {
  207.             req[0] = 0;
  208.             if (fgets (req, 79, fp) == NULL)
  209.                break;
  210.  
  211.             /* ; as the first char is a comment */
  212.             if (req[0] == ';')
  213.                continue;
  214.  
  215.             /* Get rid of the newline at the end */
  216.             s = req + strlen (req) - 1;
  217.             while ((s >= req) && isspace (*s))
  218.                *s-- = '\0';
  219.  
  220.             if (req[0] == '\0')
  221.                continue;
  222.  
  223.             if ((nfiles = n_frproc (req, nfiles, callback)) < 0)
  224.         break;
  225.             }
  226.  
  227.          sprintf (req, request_template, CurrentNetFiles,
  228.                   alias[np].Net, alias[np].Node);
  229.          errno = 0;
  230.          fclose (fp);
  231.          got_error (CLOSE_msg, req);
  232.  
  233.          /* Note that Opus does not delete this file, but we should I think */
  234.          unlink (req);
  235.          got_error (UNLINK_msg, req);
  236.          /* once we have satisfied a request, we can get out of here */
  237.          break;
  238.          }
  239.       }
  240.  
  241. done:
  242.    return fsent;
  243. }
  244.  
  245. /*
  246.  * WaZOO_callback () -- send requested file using WaZOO method.
  247.  *
  248.  *
  249.  */
  250. int WaZOO_callback (reqs)
  251. char *reqs;
  252. {
  253.    return ((*wzsendfunc) (reqs, NULL, fsent++, DO_WAZOO));
  254. }
  255.